package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUserClass;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISysUserClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户课程链接Controller
 *
 * @author ruoyi
 * @date 2025-06-27
 */
@RestController
@RequestMapping("/system/user/class")
public class SysUserClassController extends BaseController
{
    @Autowired
    private ISysUserClassService sysUserClassService;

    /**
     * 查询用户课程链接列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserClass sysUserClass)
    {
        startPage();
        List<SysUserClass> list = sysUserClassService.selectSysUserClassList(sysUserClass);
        return getDataTable(list);
    }

    /**
     * 导出用户课程链接列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:export')")
    @Log(title = "用户课程链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserClass sysUserClass)
    {
        List<SysUserClass> list = sysUserClassService.selectSysUserClassList(sysUserClass);
        ExcelUtil<SysUserClass> util = new ExcelUtil<SysUserClass>(SysUserClass.class);
        util.exportExcel(response, list, "用户课程链接数据");
    }

    /**
     * 获取用户课程链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:class:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return success(sysUserClassService.selectSysUserClassByClassId(classId));
    }

    /**
     * 新增用户课程链接
     */
    @PreAuthorize("@ss.hasPermi('system:class:add')")
    @Log(title = "用户课程链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserClass sysUserClass)
    {
        return toAjax(sysUserClassService.insertSysUserClass(sysUserClass));
    }

    /**
     * 修改用户课程链接
     */
    @PreAuthorize("@ss.hasPermi('system:class:edit')")
    @Log(title = "用户课程链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserClass sysUserClass)
    {
        return toAjax(sysUserClassService.updateSysUserClass(sysUserClass));
    }

    /**
     * 删除用户课程链接
     */
    @PreAuthorize("@ss.hasPermi('system:class:remove')")
    @Log(title = "用户课程链接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
        return toAjax(sysUserClassService.deleteSysUserClassByClassIds(classIds));
    }
}